﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace 卷书.Utils
{
    public static class Encrypt
    {
        public static string GetFileMD5(string filename)
        {
            using (var md5 = MD5.Create())
            {
                using (var stream = File.OpenRead(filename))
                {
                    return BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLower();
                }
            }
        }

        public static string GetStringMD5(string str)
        {
            using (var md5 = MD5.Create())
            {
                var tmpSource = ASCIIEncoding.ASCII.GetBytes(str);
                return BitConverter.ToString(md5.ComputeHash(tmpSource)).Replace("-", "").ToUpper();
            }
        }
    }
}
